package com.fancy.study.demo.config;

import com.fancy.study.demo.handler.DemoHandleProvider;
import com.fancy.study.demo.handler.HandleFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HandleFactoryConfigurer {

    @Bean
    public HandleFactory handleFactory(ObjectProvider<DemoHandleProvider> providers) {
        HandleFactory handleFactory = eventType -> providers.stream()
                .filter(provider -> provider.support(eventType))
                .findAny()
                .orElse(null);

        return handleFactory;
    }
}
